package com.shh.rabbitmq.direct;

import java.util.HashMap;
import java.util.Map;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectRabbitMqConfiguration {

	 //1.声明注册direct模式的交换机
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct_order_exchange",true,false);
    }
    //2.声明队列
    @Bean
    public Queue  directsmsQueue(){
    	Map<String,Object> args = new HashMap<>();
    	args.put("x-dead-letter-exchange","dead_order_exchange");//设置私信队列
        args.put("x-dead-letter-routing-key","order");//fanout不需要配置
        return new Queue("order.direct.queue",true,false,false,args);
    }
    //3.完成绑定关系
    @Bean
    public Binding  directsmsBingding(){
        return BindingBuilder.bind( directsmsQueue()).to(directExchange()).with("order");
    }
}
